<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<c:url var="action" value="/user/save.html" />
<form:form method="POST" commandName="user" action="${action}" id="mainForm">
	<div id="layout-main-right-content">
		<div id="dialog-form" title="用户"> 
		<input type="hidden" name="id" id="id" value="${user.id}" />
					<div class="yui3-g">
						<div class="yui3-u-1-6">
							<div class="content">
								<label for="loginName">登录名</label>
							</div>
						</div>
						<div class="yui3-u-1-3">
							<div class="content">
								<input type="text" name="loginName" id="loginName"
									value="${user.loginName}"
									class="text ui-widget-content ui-corner-all" />
								<form:errors path="loginName" cssClass="ui-state-error ui-corner-all" />
							</div>
						</div>
						<div class="yui3-u-1-6">
							<div class="content">
								<label for="password">密码</label>
							</div>
						</div>
						<div class="yui3-u-1-3">
							<div class="content">
								<input type="password" name="password" id="password"
									value="${user.password}"
									class="text ui-widget-content ui-corner-all" />
							</div>
						</div>
					</div>
					<div class="yui3-g">
						<div class="yui3-u-1-6">
							<div class="content">
								<label for="name">姓名</label>
							</div>
						</div>
						<div class="yui3-u-1-3">
							<div class="content">
								<input type="text" name="name" id="name" value="${user.name}"
									class="text ui-widget-content ui-corner-all" />
							</div>
						</div>
						<div class="yui3-u-1-6">
							<div class="content">
								<label for="code">用户代码</label>
							</div>
						</div>
						<div class="yui3-u-1-3">
							<div class="content">
								<input type="text" name="code" id="code" value="${user.code}"
									class="text ui-widget-content ui-corner-all" />
							</div>
						</div>
					</div>
					<div class="yui3-g">
						<div class="yui3-u-1-6">
							<div class="content">
								<label for="email">邮件</label>
							</div>
						</div>
						<div class="yui3-u-1-3">
							<div class="content">
								<input type="text" name="email" id="email" value="${user.email}"
									class="text ui-widget-content ui-corner-all" />
								<form:errors path="email" cssClass="ui-state-error ui-corner-all" />
							</div>
						</div>
						<div class="yui3-u-1-6">
							<div class="content">
								<label for="sex">性别</label>
							</div>
						</div>
						<div class="yui3-u-1-3">
							<div class="content">
								<select name="sex" id="sex">
									<option value="" <c:if test="${user.sex==''}">selected</c:if>>请选择</option>
									<option value="F" <c:if test="${user.sex=='F'}">selected</c:if>>Female</option>
									<option value="M" <c:if test="${user.sex=='M'}">selected</c:if>>Male</option>
								</select>
							</div>
						</div>
					</div>
					<div class="yui3-g">
						<div class="yui3-u-1-6">
							<div class="content">
								<label for="birthDate">生日</label>
							</div>
						</div>
						<div class="yui3-u-1-3">
							<div class="content">
								<input type="text" name="birthDate" id="birthDate"
									value="<fmt:formatDate pattern="yyyy-MM-dd" value="${user.birthDate}" />"
									class="text ui-widget-content ui-corner-all" />
							</div>
						</div>
						<div class="yui3-u-1-6">
							<div class="content">
								<label for="status">用户状态</label>
							</div>
						</div>
						<div class="yui3-u-1-3">
							<div class="content">
								<select name="status" id="status">
									<option value=""
										<c:if test="${user.status==''}">selected</c:if>>请选择</option>
									<option value="A"
										<c:if test="${user.status=='A'}">selected</c:if>>Active</option>
									<option value="I"
										<c:if test="${user.status=='I'}">selected</c:if>>Inactive</option>
								</select>
							</div>
						</div>
					</div>
					<div class="yui3-g">
						<div class="yui3-u-1-6">
							<div class="content">创建时间</div>
						</div>
						<div class="yui3-u-1-3">
							<div class="content">
								<fmt:formatDate pattern="yyyy-MM-dd HH:mm:ss"
									value="${user.createTime}" />
							</div>
						</div>
						<div class="yui3-u-1-6">
							<div class="content">更新时间</div>
						</div>
						<div class="yui3-u-1-3">
							<div class="content">
								<fmt:formatDate pattern="yyyy-MM-dd HH:mm:ss"
									value="${user.updateTime}" />
							</div>
						</div>
					</div>
					<div class="yui3-g">
						<div class="yui3-u-1-6">
							<div class="content">登录时间</div>
						</div>
						<div class="yui3-u-1-3">
							<div class="content">
								<fmt:formatDate pattern="yyyy-MM-dd HH:mm:ss"
									value="${user.loginTime}" />
							</div>
						</div>
						<div class="yui3-u-1-6">
							<div class="content">&nbsp;</div>
						</div>
						<div class="yui3-u-1-3">
							<div class="content">&nbsp;</div>
						</div>
					</div>
					<div class="yui3-g">
						<div class="yui3-u-1">
							<input type="button" id="save" value="保存" class="button_selector" />
							&nbsp;&nbsp;&nbsp;&nbsp; <input type="button" id="cancel"
								value="取消" class="button_selector"
								onclick="location.href='<c:url value="/user/list.html"/>'" />
						</div>
					</div>		
		</div>	
		<div id="tabs">
			<table class="tablesorter" id="mainTable" cellspacing="1">
						<thead>
							<tr>
								<th style="width:50px;">选择</th>
								<th class="header">ID</th>
								<th class="header">代码</th>
								<th class="header">名称</th>
								<th class="header">描述</th>
							</tr>
						</thead>
						<tbody>
							<c:set var="i" scope="page" value="0" />
							<c:forEach var="role" items="${roles}">
								<tr class=<c:if test="${(i % 2) == 0}">"odd"</c:if>
									<c:if test="${(i % 2) == 1}">"even"</c:if>>
									<td><form:checkbox path="rids" value="${role.id}"/></td>
									<td>${role.id}</td>
									<td>${role.code}</td>
									<td>${role.name}</td>
									<td>${role.desc}</td>
								</tr>
								<c:set var="i" scope="page" value="${i+1}" />
							</c:forEach>
						</tbody>
			</table>			
		</div>
	</div>
</form:form>
<script type="text/javascript">
	jQuery(function($) {
		$("#birthDate").datepicker({
			dateFormat : 'yy-mm-dd',
			showOn : "button",
			buttonImage : "${ctx}/img/calendar.gif",
			buttonImageOnly : true
		});
		
		<c:if test="${not empty user.roles}">
		$("#mainTable").tablesorter({
			sortList : [ [ 1, 0 ] ],
			widgets : [ 'zebra' ]
		}); 
		</c:if>

		$("#save").click(function() {
			var roleIds = [];
			$("input[name=chkSelected]:checked").each(function () {
				roleIds.push($(this).val()); 
			});		
			//$("#rids").val(roleIds);
			$("#mainForm").submit();
		})
		
		$(".button_selector").button();

	});
</script>